<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8"/>
</head>
<body>
<form class="layui-form" lay-filter="add-data-form">
    <div class="layui-row" style="padding: 20px;">
        ${%^fields^%}
    </div>
    <div class="layui-col-xs5">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn my-submit" lay-submit lay-filter="formDemo">
                    保存
                </button>
                <button type="button" class="layui-btn layui-btn-primary"
                        onclick="history.go(0)">
                    清空
                </button>
                <button type="button" class="layui-btn layui-btn-primary"
                        onclick="window.history.go(-1)">
                    返回
                </button>
            </div>
        </div>
    </div>
</form>

<jsp:include page="/WEB-INF/global/import.jsp"/>
<link rel="stylesheet" type="text/css" href="css/public-add.css"/>

<script type="text/javascript">

    (function () {
        let tips = "${tips}"
        if (!tips) {
            tips = getUrlParam("tips")
        }
        if (tips) {
            layer.msg(tips)
        }
    })()

    layui.use(['form'], function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.confirm('确认修改信息', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                add(data.field)
            }, function () {
            });
            return false;
        });

        function add(data) {
            $.ajax({
                url: "/${%^tableName^%}/insert",
                type: "post",
                contentType: "application/json",
                data: JSON.stringify(data),
                success(res) {
                    layer.msg(res.msg)
                },
                error(err) {
                    layer.msg(JSON.stringify(err))
                }
            })
        }

    });

</script>

</body>
</html>

